package com.business.yang.core;

import android.app.Activity;
import android.app.Application;
import android.os.Bundle;
import android.support.compat.BuildConfig;
import android.support.multidex.MultiDexApplication;

import com.lyxs916.corelib.core.application.ActivityManager;
import com.lyxs916.corelib.core.application.Global;
import com.lyxs916.utilslibrary.network.NetworkConnectionType;

import butterknife.ButterKnife;

/**
 * 说明:继承MultiDexApplication 这个对象是为了5.0以下的系统报走出方法异常
 * 作者： 杨阳; 创建于：  2017-06-01  17:44
 */
public class MyApplication extends MultiDexApplication {

    @Override
    public void onCreate() {
        super.onCreate();
        registerActivityLifecycleCallbacks(activityLifecycleCallbacks);
        NetworkConnectionType.onReceive(this);
        Global.init(this);
        initOther();

    }

    /**
     * 第三方库的初始化与设置
     */
    private void initOther() {
        ButterKnife.setDebug(BuildConfig.DEBUG);
    }

    Application.ActivityLifecycleCallbacks activityLifecycleCallbacks = new Application.ActivityLifecycleCallbacks() {
        @Override
        public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
            ActivityManager.getInstance().pushActivity(activity);

        }

        @Override
        public void onActivityStarted(Activity activity) {
        }

        @Override
        public void onActivityResumed(Activity activity) {
        }

        @Override
        public void onActivityPaused(Activity activity) {
        }

        @Override
        public void onActivityStopped(Activity activity) {
        }

        @Override
        public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
        }

        @Override
        public void onActivityDestroyed(Activity activity) {
            ActivityManager.getInstance().exitActivity(activity);
        }
    };

}
